package com.genius.smsbase.ExceptionHandler;

import com.genius.smsbase.Domain.Result;
import com.genius.smsbase.Exception.SystemException;
import com.genius.smsbase.util.ResultUtil;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @ClassName ErrorHandle
 * @Description ErrorHandle 错误处理
 * @author：
 */
@ControllerAdvice
public class ErrorHandle {

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public Result Handle(Exception e){
        if(e instanceof SystemException){
            SystemException systemException = (SystemException)e;
            return ResultUtil.error(((SystemException) e).getCode(),e.getMessage());
        }else{
            e.printStackTrace();
            return ResultUtil.error(-1,"未知错误");
        }
    }


}
